package com.keyancompany.zhongbaopingtai.weight;

import android.content.Context;
import android.view.View;
import android.widget.DatePicker;
import android.widget.NumberPicker;
import android.widget.TextView;

import com.keyancompany.zhongbaopingtai.R;

import java.util.Calendar;

import butterknife.Bind;
import butterknife.OnClick;

/**
 * Created by firefox on 2016/6/17.
 */
public class DatePopupWindow extends MenuPopuWindow {


    @Bind(R.id.datePicker)
    DatePicker datePicker;
    @Bind(R.id.select_sure)
    TextView selectSure;

    int year, month, day;

    public DatePopupWindow(Context context) {
        super(context);
    }

    @Override
    public void setUpViews() {
        Calendar calendar = Calendar.getInstance();
        int cYear = calendar.get(Calendar.YEAR);
        int monthOfYear = calendar.get(Calendar.MONTH);
        int dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH);
        year = cYear;
        month = monthOfYear;
        day = dayOfMonth;
        datePicker.init(year, monthOfYear, dayOfMonth, new DatePicker.OnDateChangedListener() {

            public void onDateChanged(DatePicker view, int cYear,
                                      int monthOfYear, int dayOfMonth) {
//                dateEt.setText("您选择的日期是："+year+"年"+(monthOfYear+1)+"月"+dayOfMonth+"日。");
//                if (cliclSureListener != null) {
//                    cliclSureListener.clickSureListner(new String[]{year + "年", (monthOfYear + 1) + "月", dayOfMonth + "日" });
//                }
//                dateValue = new String[]{year + "", (monthOfYear + 1) + "",
//                        dayOfMonth + ""};
                year = cYear;
                month = monthOfYear;
                day = dayOfMonth;
            }

        });
//        datePicker.ini
    }

    void setDate(int cYear, int monthOfYear, int dayOfMonth) {
        this.year = cYear;
        this.month = monthOfYear;
        this.day = dayOfMonth;
    }

    @Override
    public void setUpListener() {

    }

    @OnClick(R.id.select_sure)
    public void selectResult(View view) {
        if (dateListener != null) {
            dateListener.selectDate(year, month, day);
        }
        dismiss();
    }

    @Override
    public int getAnimationStyle() {
        return 0;
    }

    @Override
    public int getResView() {
        return R.layout.popup_data_picker;
    }

    @Override
    public void updateView(View contentView) {

    }

    IOnSelectDateListener dateListener;

    public void setDateListener(IOnSelectDateListener dateListener) {
        this.dateListener = dateListener;
    }

    public interface IOnSelectDateListener {
        void selectDate(int year, int moth, int day);
    }
}
